use common::file_system::{join_paths, write_to_file};
use common::util::run_command;
use std::path::{Path, PathBuf};

pub fn init_vue_project(
    install_dir: &Path,
    project_name: &str,
    package_json_content: &str,
) -> Result<PathBuf, Box<dyn std::error::Error>> {
    write_to_file(
        &join_paths(install_dir, Path::new("package.json")),
        package_json_content,
    )?;

    run_command(
        install_dir,
        "npx",
        &["create-vite", project_name, "--template", "vue-ts", "-y"],
    )
    .inspect_err(|_| eprintln!("运行create-vite失败"))?;

    let project_path = install_dir.join(project_name);
    println!("Project created successfully");

    Ok(project_path)
}
